﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model;

namespace l1cs.server.serverpackets
{
    public class S_MoveCharPacket : ServerBasePacket
    {
        private static Logger _log = Logger.getLogger( typeof( S_MoveCharPacket ).FullName );

        private byte[] _byte = null;

        public S_MoveCharPacket( L1Character cha )
        {
            int x = cha.getX();
            int y = cha.getY();
            // if(cha instanceof L1PcInstance)
            // {

            switch ( cha.getHeading() )
            {
                case 1: // '\001'
                    x--;
                    y++;
                    break;

                case 2: // '\002'
                    x--;
                    break;

                case 3: // '\003'
                    x--;
                    y--;
                    break;

                case 4: // '\004'
                    y--;
                    break;

                case 5: // '\005'
                    x++;
                    y--;
                    break;

                case 6: // '\006'
                    x++;
                    break;

                case 7: // '\007'
                    x++;
                    y++;
                    break;

                case 0: // '\0'
                    y++;
                    break;
            }

            writeC( Opcodes.S_OPCODE_MOVEOBJECT );
            writeD( cha.getId() );
            writeH( x );
            writeH( y );
            writeC( cha.getHeading() );
            writeC( 129 );
            writeD( 0 );
        }

        override
        public byte[] getContent()
        {
            if ( _byte == null )
            {
                _byte = getBytes();
            }
            return _byte;
        }

        override
        public String getType()
        {
            return "[S] S_MoveCharPacket";
        }
    }
}
